package com.platform.comm.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.nio.file.Paths;

/**
 * @author Tommy
 */
@Component
public class ProjectUtils {

    private static String FILE_ROOT_PATH;

    @Value("${admin.file-root-path}")
    public void setFileRootPath(String cfgValue){
        FILE_ROOT_PATH = cfgValue;
    }

    private static String getDirRootPath(String moduleName) {
        return Paths.get(FILE_ROOT_PATH, moduleName).toString();
    }

    private static String getUploadRootPath(String moduleName) {
        return Paths.get(getDirRootPath(moduleName), "upload").toString();
    }

    private static String getThumbnailRootPath(String moduleName) {
        return Paths.get(getDirRootPath(moduleName), "thumbnail").toString();
    }

    public static String getTemplateRootPath(String moduleName) {
        return Paths.get(getDirRootPath(moduleName), "template").toString();
    }

    private static String getExportRootPath(String moduleName) {
        return Paths.get(getDirRootPath(moduleName), "export").toString();
    }

    public static String getImportFilePath(String moduleName,String path) {
        return Paths.get(getUploadRootPath(moduleName), path).toString();
    }

    public static String getThumbnailPath(String moduleName,String path) {
        return Paths.get(getThumbnailRootPath(moduleName), path).toString();
    }

    public static String getCmsPath(String funName, String moduleName,String path) {
        return Paths.get(getUploadRootPath(funName), moduleName , path).toString();
    }

    public static String getTemplateFilePath(String moduleName,String path) {
        return Paths.get(getTemplateRootPath(moduleName), path).toString();
    }

    public static String getExportFilePath(String moduleName,String path) {
        return Paths.get(getExportRootPath(moduleName), path).toString();
    }

    public static String getValidationErrorFilePath(String moduleName, String path) {
        return UploadUtil.buildErrorFileName(getImportFilePath(moduleName,path), "error-", "", "xlsx");
    }

    public static String getValidationErrorFilePath(String moduleName, String path, String extName) {
        return UploadUtil.buildErrorFileName(getImportFilePath(moduleName,path), "error-", "", extName);
    }

    public static String getRepeatErrorFilePath(String moduleName, String path) {
        return UploadUtil.buildErrorFileName(getImportFilePath(moduleName, path), "repeat-", "", "xlsx");
    }

    public static String getExcelExportFilePath(String moduleName, String path) {
        return UploadUtil.buildErrorFileName(getExportFilePath(moduleName, path), "export-", "", "xlsx");
    }

    public static String getEvalCalFilePath(String moduleName, String path) {
        return UploadUtil.buildErrorFileName(getImportFilePath(moduleName,path), "eval-", "", "xlsx");
    }

    public static String getExportFilePath(String moduleName, String path, String prefix, String extName) {
        return UploadUtil.buildErrorFileName(getExportFilePath(moduleName, path), prefix, "", extName);
    }

    public static String getDownloadRootPath(String moduleName) {
        return Paths.get(getDirRootPath(moduleName), "download").toString();
    }
}
